//
//  BankAllMenu.m
//  bank_ipad2
//
//  Created by nxj bill on 12-3-14.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "Menu.h"

#import "Constants.h"
#import "XMLParse.h"

extern XMLParse* GOLOBXP;

const NSInteger kViewTag = 1;
@implementation Menu

@synthesize dataDict,dataSourceArray;
#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
	self.title=@"银行菜单";

	
	UIImageView * image;
	UILabel * label;
	
	image = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 0, 0)];
	image.image= [UIImage imageNamed:kBackground];
	[image setBackgroundColor:[UIColor clearColor]];	
	self.tableView.backgroundView = image;
	[image release];
	
	self.dataSourceArray = [NSMutableArray array];
	
	NSString *src;
	NSString *id;
	NSString *text;
	int count = [GOLOBXP intValue:@"getmenulength('accountquery')"];
	for (int i=0; i<count; i++) {
		src = [GOLOBXP getElementValue:[NSString stringWithFormat:@"getmenu('accountquery','%d','src')",i]];
		id = [GOLOBXP getElementValue:[NSString stringWithFormat:@"getmenu('accountquery','%d','id')",i]];
		text = [GOLOBXP getElementValue:[NSString stringWithFormat:@"getmenu('accountquery','%d','text')",i]];
		NSLog(src);
	
	
	
		
		label = [[UILabel alloc] initWithFrame: CGRectMake( 42.0,5.0,100.0,30.0)];
		[label setBackgroundColor:[UIColor clearColor]];	
		label.text = text;
		label.tag = kViewTag;
		
		
		image = [[UIImageView alloc] initWithFrame: CGRectMake(0.0, 5.0, 40, 40)];
		image.image= [UIImage imageNamed:src];
		[image setBackgroundColor:[UIColor clearColor]];
		
		
		
		[self.dataSourceArray addObject:[NSArray arrayWithObjects:label,image,nil]];
		
		[label release];
		[image release];
	}
	
	
	
	
	}

 - (void)viewWillAppear:(BOOL)animated {
 [super viewWillAppear:animated];
	 
//	 NSString *filePathOfIndex = [[NSBundle mainBundle] pathForResource:@"bankallmenuhelp.html" ofType:nil];
//	 NSString *strAbsPath= [NSString stringWithFormat:@"encodeURI('file:///%@')",filePathOfIndex];
//	 NSString *url  = [detailViewController.detailDescriptionWeb stringByEvaluatingJavaScriptFromString:strAbsPath];
//	 [detailViewController.detailDescriptionWeb stopLoading];
//	 [detailViewController.detailDescriptionWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
//	 
//	 
 }


/*
 - (void)viewDidAppear:(BOOL)animated {
 [super viewDidAppear:animated];
 }
 */
/*
 - (void)viewWillDisappear:(BOOL)animated {
 [super viewWillDisappear:animated];
 }
 */
/*
 - (void)viewDidDisappear:(BOOL)animated {
 [super viewDidDisappear:animated];
 }
 */

// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
	
    interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}


#pragma mark -
#pragma mark Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
//    // Return the number of sections.
//	//NSArray* temp = [dataSourceArray objectAtIndex:indexPath.section];
//	
//    return [dataSourceArray count];
//}


- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
	
	return [dataSourceArray count];
	
}


//系统
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	
	return ([indexPath row] == 0) ? 50.0 : 50.0;
}

//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//{
//	NSArray* temp = [dataSourceArray objectAtIndex:section];
//	NSString *s = [[temp objectAtIndex: 0] objectAtIndex:3];
//	return s;
//}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
	static NSString *CellIdentifier = @"CellIdentifier";
    
    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
	
	UILabel *label;
	label = [[self.dataSourceArray objectAtIndex: indexPath.row] objectAtIndex:0];
	[cell.contentView addSubview:label];
	
	UIImageView *image;
	image = [[self.dataSourceArray objectAtIndex: indexPath.row] objectAtIndex:1];
	[cell.contentView addSubview:image];
	
    return cell;
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */


/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
 }   
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }   
 }
 */


/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */


/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    detailViewController.detailItem = [NSString stringWithFormat:@"Row %d", indexPath.row];
//	
//
//	NSArray* temp = [dataSourceArray objectAtIndex:indexPath.section];
//	
//	NSString *url = [[temp objectAtIndex: indexPath.row] objectAtIndex:2];
//	[detailViewController.detailDescriptionWeb stopLoading];
//	[detailViewController.detailDescriptionWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
	
	dataDict= nil;
	dataSourceArray= nil;
}


- (void)dealloc {
	[dataDict release];
	[dataSourceArray release];
    [super dealloc];
}


@end



